﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ScaffoldIt;

namespace ScaffoldItConfig
{
    using ScaffoldIt.Configuration;

    public partial class FormMain : Form
    {
        private FormScaffoldItConfig _ctrl;

        public FormMain()
        {
            _ctrl = new FormScaffoldItConfig();
            _ctrl.OnSaveConfig = new FormScaffoldItConfig.SaveConfigHandler(AutoSave);
            this.Controls.Add(_ctrl);

            _ctrl.Dock = DockStyle.Fill;
            InitializeComponent();
        }

        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                var cfg = ScaffoldItConfig.Load(openFileDialog1.FileName);                
                _ctrl.Init(cfg);
            }
        }

        private void AutoSave(ScaffoldIt.Configuration.ScaffoldItConfig cfg)
        {            
            cfg.Save();
        }
    }
}
